package com.woniu.new_orange.staff_module_dong.service.impl;

import com.woniu.new_orange.entity.Dept;
import com.woniu.new_orange.entity.Staff;
import com.woniu.new_orange.mapper.DeptMapper;
import com.woniu.new_orange.mapper.StaffMapper;
import com.woniu.new_orange.staff_module_dong.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Program: new_orange->DeptServiceImpl
 * @Description:
 * @Author: donghang
 * @Date: 2023-01-31 16:18
 * @Version： 1.0
 **/
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;
    @Autowired
    private StaffMapper staffMapper;
    @Override
    public List<Dept> selAll() {
        return deptMapper.selAll();
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        List<Staff> staff = staffMapper.selByDeptId(id);
        if(staff.size() == 0){
            return deptMapper.deleteByPrimaryKey(id);
        } else {
            return 8;
        }

    }

    @Override
    public int insert(Dept record) {
        return deptMapper.insert(record);
    }

    @Override
    public int insertSelective(Dept record) {
        return deptMapper.insertSelective(record);
    }

    @Override
    public Dept selectByPrimaryKey(Long id) {
        return deptMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Dept record) {
        return deptMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Dept record) {
        return deptMapper.updateByPrimaryKey(record);
    }
}
